// 角色管理
import request from '@/utils/request'
import type { MenuResponseData, RoleData, RoleResponseData } from './type'
enum API {
  // 获取职位列表
  ALLROLE_URL = '/admin/acl/role/',
  // 添加职位
  ADDROLE_URL = '/admin/acl/role/save',
  // 修改职位
  UPDATEROLE_URL = '/admin/acl/role/update',
  // 删除职位
  REMOVEROLE_URL = '/admin/acl/role/remove/',
  // 获取全部的菜单与按钮数据
  ALLPERMISSION = '/admin/acl/permission/toAssign/',
  // 给职位分配权限
  SETPERMISSION_URL = '/admin/acl/permission/doAssign/'
}


// 获取所有职位
export const reqAllRole = (page:number, limit:number, roleName:string) => request.get<any,RoleResponseData>(API.ALLROLE_URL+`${page}/${limit}?roleName=${roleName}`)

// 添加更新职位
export const reqAddOrUpdateRole = (data:RoleData) => {
  if(data.id) {
    return request.put<any, any>(API.UPDATEROLE_URL, data)
  } else {
    return request.post<any, any>(API.ADDROLE_URL, data)
  }
}

// 删除已有职位
export const reqRemoveRole = (roleId:number) => request.delete<any, any>(API.REMOVEROLE_URL+`${roleId}`)

// 获取全部的菜单与按钮
export const reqAllMenuList = (roleId: number) => request.get<any, MenuResponseData>(API.ALLPERMISSION+`${roleId}`)

// 给职位分配权限
export const reqSetPermission = (roleId:number,permissionId:number[]) => request.post<any, any>(API.SETPERMISSION_URL+`?roleId=${roleId}&permissionId=${permissionId}`)






